package com.jy.rhin.support.polymorphism.convertor;

import cn.org.chiss.rhin._2015.document.management.DocumentStoredQueryResponse;
import com.jy.rhin.sdk.dto.document.DocumentAssociationDto;
import com.jy.rhin.sdk.dto.document.DocumentResultDto;
import com.jy.rhin.sdk.dto.document.query.GetRelatedDocumentsDto;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author dhl
 * @date 2022/6/22
 * @Description
 */
@Service("getRelatedDocuments")
public class DocumentQueryHandler4GetRelatedDocuments extends AbstractDocumentQueryHandler<GetRelatedDocumentsDto, DocumentAssociationDto>{
    @Override
    GetRelatedDocumentsDto convertReq(Map<String, List<String>> dtoValueMap) {
        GetRelatedDocumentsDto dto = new GetRelatedDocumentsDto();
        dto.setTypeCodeList(QueryValueUtils.getListValue("$AssociationTypes", dtoValueMap));
        dto.setId(QueryValueUtils.getStringValue("$DocumentEntryUUID", dtoValueMap));
        dto.setUniqueId(QueryValueUtils.getStringValue("$DocumentEntryUniqueId", dtoValueMap));
        dto.setHomeCommunityId(QueryValueUtils.getStringValue("$HomeCommunityId", dtoValueMap));
        return dto;
    }

    @Override
    DocumentResultDto<DocumentAssociationDto> query(GetRelatedDocumentsDto dto) {
        return documentSubmissionQueryHandler.getRelatedDocuments(dto);
    }

    @Override
    DocumentStoredQueryResponse convertResp(List<DocumentAssociationDto> resultList, List<String> jsonTextList) {
        return associationConvert(resultList, jsonTextList);
    }
}
